package com.nf.health.app.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.inquiry.docdetail.DocDetailActivity;
import com.nf.health.app.models.DoctorVo;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

/*
*
* w我的医生  查找    适配器   去除  侧滑功能
*/

public class SearchDoctorAdapter extends BaseAdapter{

	protected static final String TAG = SearchDoctorAdapter.class.getSimpleName();
	private Activity context;
	private List<DoctorVo> doctors;

	public SearchDoctorAdapter(Activity context, List<DoctorVo> doctors) {
		this.context = context;
		this.doctors = doctors;

	}

	@Override
	public int getCount() {
		if (doctors != null) {
			return doctors.size();
		}
		return 10;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_my_doctor_search, position);
		ImageView iv_user_head_icon = holder.getView(R.id.iv_user_head_icon);
		ImageLoaderUtils.getinstance(context).getImage(iv_user_head_icon, doctors.get(position).getDoctorhimg(), R.drawable.moren_doctor_image);

		if(TextUtils.isEmpty(doctors.get(position).getDoctorname())||doctors.get(position).getDoctorname()==null||doctors.get(position).getDoctorname().equals("")){
			holder.setText(R.id.doctor_name, doctors.get(position).getNick());
		}else{
			holder.setText(R.id.doctor_name, doctors.get(position).getDoctorname());
		}

		holder.setText(R.id.doctor_professional, doctors.get(position).getProfessional());
		holder.setText(R.id.doctor_hospitalname, doctors.get(position).getHospitalname()+" - "+doctors.get(position).getDepartment());
		View ll_content  = holder.getView(R.id.ll_content);


		ll_content.setTag(position);
		ll_content.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Bundle bundle = new Bundle();
				bundle.putString(DocDetailActivity.DOCTORID,doctors.get(position).getDoctorid());
				ActivityUtils.showActivity(context,DocDetailActivity.class,bundle);
			}
		});

		return holder.getConvertView();
	}
}
